package uy.edu.um.ltic.server.persistence;

import static org.junit.Assert.*;

import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;

import javax.imageio.ImageIO;

import org.junit.Test;

import uy.edu.um.ltic.exception.DataBaseException;

public class getFiles {

	@Test
	public void test() {
		MessageDAOMgt oMessage = MessageDAOFactory.getInstance().getMessageDAOMgt();
		ArrayList<Integer> files;
		
		try {
			files = oMessage.getFilesFromOneEmployeeToAnother(2, 1);
			assertEquals(files.get(0), Integer.valueOf(1));
			String name = oMessage.getNameOfFile(1);
			assertEquals(name, "Archivo");
		} catch (DataBaseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		byte[] file = null;
		try {
			file = oMessage.getFile(1);
		} catch (DataBaseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		BufferedImage originalImage = null;
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		byte[] imageInByte = null;
		try {
			originalImage = ImageIO.read(getClass().getResource("/images.jpeg"));
			ImageIO.write( originalImage, "jpg", baos );
			baos.flush();
			imageInByte = baos.toByteArray();
			baos.close();
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		assertEquals(file[1], imageInByte[1]);
		assertEquals(file[120], imageInByte[120]);
		
	}

}
